package com.ysy.facade;


import com.ysy.api.UserFeignApi;
import com.ysy.dto.IdRequestDTO;
import com.ysy.dto.IdsRequestDTO;
import com.ysy.dto.UserDTO;
import com.ysy.enums.ResponseCodeEnum;
import com.ysy.persimmons.common.constant.HttpStatus;
import com.ysy.persimmons.common.response.Response;
import com.ysy.persimmons.common.util.AssertUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UserFeignService {


    @Resource
    private UserFeignApi userFeignApi;


    /**
     *
     * @param id
     * @return
     */
    public UserDTO findById(Long id) {
       IdRequestDTO idRequestDTO = new IdRequestDTO();
       idRequestDTO.setId(id);
       Response<UserDTO> response = userFeignApi.findById(idRequestDTO);
       if (response.getCode()!=HttpStatus.SUCCESS) {
           return null;
       }
       return response.getData();
    }

    /**
     * 批量查询
     * @param ids
     * @return List<UserDTO>
     */
    public List<UserDTO> findByIds(List<Long> ids) {
        IdsRequestDTO idsRequestDTO = new IdsRequestDTO();
        idsRequestDTO.setIds(ids);
        Response<List<UserDTO>> response = userFeignApi.findByIds(idsRequestDTO);
        if (response.getCode()!=HttpStatus.SUCCESS) {
            return null;
        }
        return response.getData();
    }
}
